/*
 * hudong.com Inc.
 * Copyright (c) 2000-2004 All Rights Reserved.
 */
package middlegen.plugins.ibatis;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import middlegen.plugins.ibatis.config.ColumnConfig;
import middlegen.plugins.ibatis.config.ResultMapConfig;

/**
 * An implementation of ResultMap interface.
 * 
  */
public class IWalletResultMap implements ResultMap {
    /** the table to which the result map belongs */
    protected IWalletTable table;

    protected String       idAttr;

    protected String       classAttr;

    protected List         results = new ArrayList();

    public IWalletResultMap(IWalletTable table, ResultMapConfig config) {
        if (config == null) {
            // construct the default result map
            idAttr = table.getResultMapId();
            classAttr = table.getQualifiedDOClassName();

            
            Iterator i = table.getColumns().iterator();
            while (i.hasNext()) {
                results.add(new IWalletResultMapResult((IWalletColumn) i.next() ) );
            }
        } else {
            idAttr = config.getName();
            /*
             * TODO: make the class attribute customizable
             */
            classAttr = table.getQualifiedDOClassName();

            Iterator i = config.getColumns().iterator();
            while (i.hasNext()) {
                ColumnConfig cc = (ColumnConfig) i.next();
                results.add(new IWalletResultMapResult((IWalletColumn) table
                    .getColumn(cc.getName())));
            }
        }
    }

    /**
     * @return
     * 
     * @see middlegen.plugins.ibatis.ResultMap#getIdAttr()
     */
    public String getIdAttr() {
        return idAttr;
    }

    /**
     * @return
     * 
     * @see middlegen.plugins.ibatis.ResultMap#getClassAttr()
     */
    public String getClassAttr() {
        return classAttr;
    }

    /**
     * @return
     * 
     * @see middlegen.plugins.ibatis.ResultMap#getResults()
     */
    public List getResults() {
        return results;
    }

}
